#import "ALTimelineElementView.h"



#pragma mark Constants
static const CGFloat ALTimelineElementCornerRadius = 7.0f;


#pragma mark -
#pragma mark Class Globals
static NSGradient *ALTimelineElementBackgroundGradient;
static NSGradient *ALTimelineElementBackgroundGradientSelected;
static NSColor *ALTimelineElementBorderColor;
static NSColor *ALTimelineElementBorderColorSelected;


#pragma mark -
@interface ALTimelineElementView (ALTimelineElementViewPrivateMethods)

@end


#pragma mark -
@implementation ALTimelineElementView

@synthesize selected;

+(void)initialize {
	NSColor *startColor = [NSColor colorWithCalibratedWhite:0.2f alpha:0.3f];
	NSColor *endColor = [NSColor colorWithCalibratedWhite:0.35f alpha:0.3f];
	ALTimelineElementBackgroundGradient = [[NSGradient alloc] initWithStartingColor:startColor endingColor:endColor];
	
	NSColor *startSelected = [NSColor colorWithCalibratedRed:0.302 green:0.461 blue:0.621 alpha:1.000];
	NSColor *endSelected = [NSColor colorWithCalibratedRed:0.605 green:0.645 blue:0.727 alpha:1.000];
	ALTimelineElementBackgroundGradientSelected = [[NSGradient alloc] initWithStartingColor:startSelected endingColor:endSelected];
	
	ALTimelineElementBorderColor = [NSColor colorWithCalibratedWhite:0.2f alpha:1.0f];
	ALTimelineElementBorderColorSelected = [NSColor colorWithCalibratedRed:0.606 green:0.671 blue:0.783 alpha:1.000];
}

-(void)setSelected:(BOOL)shouldSelect {
	selected = shouldSelect;
	[self setNeedsDisplay:YES];
}

-(void)drawRect:(NSRect)dirtyRect {
	NSRect bounds = NSInsetRect([self bounds], 1.5f, 1.5f);
	NSBezierPath *path = [NSBezierPath bezierPathWithRoundedRect:bounds xRadius:ALTimelineElementCornerRadius yRadius:ALTimelineElementCornerRadius];
	NSGradient *backgroundGradient = [self selected] ? ALTimelineElementBackgroundGradientSelected : ALTimelineElementBackgroundGradient;
	NSColor *borderColor = [self selected] ? ALTimelineElementBorderColorSelected : ALTimelineElementBorderColor;
	[backgroundGradient drawInBezierPath:path angle:90];
	[borderColor setStroke];
	[path stroke];
}

@end
